﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VM.Common.strFormatUntil
{
    public class StrFormat
    {
        /// <summary>
        /// 获取两个字符中间的字符串，包含中间字符及两侧字符
        /// </summary>
        /// <param name="str">原字符串</param>
        /// <param name="StartZf">起始字符</param>
        /// <param name="EndZf">末尾字符</param>
        /// <returns></returns>
        public string GetCutStr(string str, string StartZf, string EndZf)
        {
            int i = str.IndexOf(StartZf);
            int j = str.LastIndexOf(EndZf);  //最后一个出现该字符的位置
            str = (str.Substring(i)).Substring(0, j - i);//找出a和b之间的字符串
            return str;

        }

        public string AddStr(string type, string Str, string Para)
        {

            if (type == "JosnStart")
            {

                return "[" + Para + "\"" + "," + "\"" + Str;

            }
            if (type == "JosnEnd")
            {

                return Str + "\"" + "]";

            }
            else
            {
                return "";

            }

        }



        public static void WtrieStr(string str)
        {
            System.IO.File.WriteAllText(@"e:\JDHB\Log.txt", str, Encoding.UTF8);
        }

        /// <summary>
        /// 获取某个字符串中某个字符的个数
        /// </summary>
        /// <param name="FindStr">要查找的字符</param>
        /// <param name="Str">从这个字符串中查找</param>
        /// <returns></returns>
        public int GetCount(string FindStr, string Str)
        {
            int index = 0;
            int count = 0;
            while ((index = Str.IndexOf(FindStr, index)) != -1)

            {
                count++;
                // Console.WriteLine("第{0}次；索引是{1}", count, index);
                index = index + FindStr.Length;
            }
            return count;


        }


        /// <summary>
        /// 获取截取后的字符串，并返回
        /// </summary>
        /// <param name="Str">待截取的字符串</param>
        /// <param name="SplStr">字符串内的分隔符</param>
        /// <param name="i">取第几个进行返回</param>
        /// <returns></returns>
        public string GetSplitStr(string Str, char SplStr, int i)
        {
            string[] sArray = Str.Split(new char[1] { SplStr });
            return sArray[i].ToString();
        }

        /// <summary>
        /// 获取截取字符串后的字符
        /// </summary>
        /// <param name="Str"></param>
        /// <param name="StartIndex"></param>
        /// <param name="Lengt"></param>
        /// <returns></returns>
        public static string GetRemoveStr(string Str, int StartIndex, int Lengt)
        {
            string str1 = Str.Remove(StartIndex, Lengt);
            return str1;

        }


        /// <summary>
        /// 获取截取后的字符串
        /// </summary>
        /// <param name="Str"></param>
        /// <param name="StartIndex"></param>
        /// <param name="Lengt"></param>
        /// <returns></returns>
        public static string GetSpilitStr(string Str, int StartIndex, int Lengt)
        {
            string str1 = Str.Remove(StartIndex, Lengt);
            return str1;

        }

        /// <summary>
        /// 判断某个字符是否在字符串中
        /// </summary>
        /// <param name="Str">判断是否在这个中</param>
        /// <param name="SerchStr">要查找的字符串</param>
        /// <param name="IsDXX">是否区分大小写 1 区分，否则不缺分</param>
        /// <returns></returns>
        public static bool CheckIsExit(string Str, string SerchStr, int IsDXX)
        {

            bool Res = false;
            if (IsDXX == 1)
            {
                Res = Str.Contains(SerchStr);
            }
            else
            {
                Res = Str.IndexOf(SerchStr) > 0 ? true : false;
            }
            return Res;

        }

    }
}
